package mx.com.theboard.notas;

import java.io.IOException;
import java.io.OutputStream;

import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Upload;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Upload.Receiver;

public class TBNotaArchivo extends TBNota {
	public TBNotaArchivo(){
		super();
		super.setWidth("470px");
		super.setResizable(true);
		MyReceiver receiver = new MyReceiver();
		
		VerticalLayout contenido = super.getContenido();
		contenido.setHeight("100px");
		
		VerticalLayout inner = new VerticalLayout();
		inner.setStyleName("fondouplod");
		
		inner.addComponent(new Label("Selecciona el archivo a subir:"));
		Upload upload = new Upload(null, receiver);	
		inner.addComponent(upload);
		
			
		contenido.addComponent(inner);
	}
	
	 public static class MyReceiver implements Receiver {

	        private String fileName;
	        private String mtype;
	        private boolean sleep;
	        private int total = 0;

	        public OutputStream receiveUpload(String filename, String mimetype) {
	            fileName = filename;
	            mtype = mimetype;
	            return new OutputStream() {
	                @Override
	                public void write(int b) throws IOException {
	                    total++;
	                    if (sleep && total % 10000 == 0) {
	                        try {
	                            Thread.sleep(100);
	                        } catch (InterruptedException e) {
	                            // TODO Auto-generated catch block
	                            e.printStackTrace();
	                        }
	                    }
	                }
	            };
	        }

	        public String getFileName() {
	            return fileName;
	        }

	        public String getMimeType() {
	            return mtype;
	        }

	        public void setSlow(boolean value) {
	            sleep = value;
	        }

	    }

	
}


